<?php

require("./mpcamera/setup.php");

$smarty = new Smarty_MPCamera();

if (isset($_GET["getTP"])) {
    $getTP = $_GET["getTP"];
    $getTP = $smarty->clean($getTP, true);

    $query = "
        SELECT `MaTP`, `quanhuyen`.`MaQH`, `TenQH`
        FROM `quanhuyen`, `thanhpho_quanhuyen`
        WHERE `quanhuyen`.`MaQH` = `thanhpho_quanhuyen`.`MaQH`
            AND `MaTP` = $getTP
    ;";
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result)) {
        $quanhuyen[] = $row;
    }
    if (isset($quanhuyen)) {
        echo json_encode($quanhuyen, JSON_UNESCAPED_UNICODE);
    }
} else if (isset($_GET["getQH"])) {
    $getQH = $_GET["getQH"];
    $getQH = $smarty->clean($getQH, true);

    $query = "
        SELECT `MaQH`, `phuongxa`.`MaPX`, `TenPX`
        FROM `phuongxa`, `quanhuyen_phuongxa`
        WHERE `phuongxa`.`MaPX` = `quanhuyen_phuongxa`.`MaPX`
            AND `MaQH` = $getQH
    ;";
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result)) {
        $phuongxa[] = $row;
    }
    if (isset($phuongxa)) {
        echo json_encode($phuongxa, JSON_UNESCAPED_UNICODE);
    }
}